<?php


namespace app\admin\controller\setting;

use app\admin\controller\AdminController;
use app\admin\service\setting\SmsService;
use app\admin\validate\setting\SmsValidate;

use think\response\Json;

/**
 * 短息配置控制器
 */
class Sms extends AdminController
{

    /**
     * 获取短信配置列表
     * @return Json
     */
    public function lists()
    {
        return $this->success(SmsService::lists());
    }


    /**
     * 短信配置信息
     * @return Json
     */
    public function detail()
    {
        $param = (new SmsValidate())->checkParam('detail');
        return $this->success(SmsService::detail($param));
    }


    /**
     * 设置短信配置
     * @return Json
     */
    public function edit()
    {
        $params = (new SmsValidate())->post()->checkParam('edit');
        $result = SmsService::edit($params);
        if (true === $result) {
            return $this->success([], '配置成功');
        } else {
            return $this->error(SmsService::getError());
        }
    }


    /**
     * 切换短信驱动
     * @return Json
     */
    public function change()
    {
        $params = (new SmsValidate())->post()->checkParam('change');
        $result = SmsService::change($params);
        if (true === $result) {
            return $this->success([], '切换成功');
        } else {
            return $this->error(SmsService::getError());
        }
    }
}